﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TouristAgencyDataLayer
{
    public class ReservationsPersons
    {
        public static void CreateReservationPerson(int resId, int perId)
        {
            TouristAgencyDataClassesDataContext context = new TouristAgencyDataClassesDataContext();

            ReservationsPerson m = new ReservationsPerson()
            {
               PersonId = perId,
               ReservationId = resId
            };

            context.ReservationsPersons.InsertOnSubmit(m);
            context.SubmitChanges();
        }

        public static void DeleteReservationPerson(int resId, int perId)
        {

            TouristAgencyDataClassesDataContext context = new TouristAgencyDataClassesDataContext();

            var res =
                (from b in context.ReservationsPersons
                 where b.PersonId == perId && b.ReservationId == resId
                 select b).FirstOrDefault();

            if (res != null)
            {
                context.ReservationsPersons.DeleteOnSubmit(res);
                context.SubmitChanges();
            }
        }
    }
}
